<template>
	<view class="container" style="background-color: #f3f5f9;">
		<view class="title" style="margin-left: 130px;">团体预约</view>
		<view class="yuyue">
			<view class="form-group">
				<label>预约日期：</label>
				<picker mode="date" :value="date" @change="onDateChange">
					<view class="picker">{{ date }}</view>
				</picker>
			</view>
			<view class="form-group">
				<label>预约时间：</label>
				<picker mode="time" :value="time" @change="onTimeChange">
					<view class="picker">{{ time }}</view>
				</picker>
			</view>
		</view>
		<view class="team">
			<view class="form-group">
				<label>团队名称：</label>
				<input class="aaa" type="text" v-model="teamName" placeholder="请输入团队名称" />
			</view>
			<view class="form-group">
				<label>团体人数：</label>
				<input class="aaa" type="number" v-model.number="totalPeople" placeholder="请输入预约人数" />
			</view>
		</view>
		<view class="form-group" v-for="(member, index) in members" :key="index">
			<label>团体负责人 {{ index + 1 }}：</label>
			<view class="ccc">
				<view>
					<label style="font-weight: 600;">姓名：</label>
					<input class="aaa" type="text" v-model="membername" placeholder="请输入同行人姓名" />
				</view>
				<view>
					<label style="font-weight: 600;">证件类型：</label>
					<input class="aaa" type="text" v-model="memberidType" placeholder="请输入证件类型" />
				</view>
				<view>
					<label style="font-weight: 600;">证件号码：</label>
					<input class="aaa" type="text" v-model="memberidNumber" placeholder="请输入证件号码" />
				</view>
				<view>
					<label style="font-weight: 600;">手机号码：</label>
					<input class="aaa" type="number" v-model.number="memberphoneNumber" placeholder="请输入手机号码" />
				</view>
			</view>
			<button @click="removeMember(index)">删除</button>
		</view>
		<button @click="addMember">添加同行人</button>


		<view class="">

			<button @click="submitReserve">提交预约</button>

		</view>



	</view>
</template>

<script>
	export default {
		data() {
			return {
				date: '2024-7-16',
				time: '09:00:00',
				teamName: '',
				totalPeople: '',
				members: [{
					name: '',
					idType: '',
					idNumber: '',
					phoneNumber: ''
				}, ],
			};
		},

		methods: {

			onDateChange(e) {
				this.date = e.detail.value;
			},
			onTimeChange(e) {
				this.time = e.detail.value;
			},
			onIdTypeChange(e) {
				this.idTypeIndex = e.detail.value;
			},

			addMember() {
				if (this.members.length < this.totalPeople) {
					this.members.push({
						name: '',
						idType: '',
						idNumber: '',
						phoneNumber: ''
					});
				} else {
					uni.showToast({
						title: '已达到预约人数上限',
						icon: 'none'
					});
				}



			},
			removeMember(index) {
				if (this.members.length > 1) { // 假设至少保留一个成员  
					this.members.splice(index, 1);
					this.updateTotalPeople();
				}
			},
			updateTotalPeople() {
				this.totalPeople = this.members.length;
			},
			submitReserve() {
				const userData = {
					date: this.date,
					time: this.time,
					teamName: this.teamName,
					totalPeople: this.totalPeople,
					membername: this.membername,
					memberidType: this.memberidType,
					/*[this.memberidTypeIndex],*/
					memberidNumber: this.memberidNumber,
					memberphoneNumber: this.memberphoneNumber,

				};

				uni.setStorage({
					key: 'userData',
					data: JSON.stringify(userData),
					success: function() {
						console.log('数据存储成功');
						uni.navigateTo({
							url: '/pages/successfulAppoGroup/successfulAppoGroup'
						})
					}
				})


				// 这里可以添加提交到服务器的逻辑  
				const reservation = {
					teamName: this.teamName,
					totalPeople: this.totalPeople,
					members: this.members,
				};
				console.log('提交团体预约:', reservation);
				// 发送请求到服务器  
				// uni.request({...});  
			},
		},
	};
</script>

<style>
	/* 添加你的样式 */
	.container {
		padding: 20px;
	}

	.title {
		font-size: 18px;
		font-weight: bold;
		margin-bottom: 20px;
	}

	.form-group {
		margin-bottom: 15px;
		display: flex;
		flex-direction: column;
		align-items: flex-start;
	}

	.form-group label {
		margin-bottom: 5px;
	}

	.form-group button {
		margin-top: 10px;
	}

	.picker {
		padding: 10px;
		border: 1px solid #ccc;
		border-radius: 5px;
	}

	.yuyue {
		border: 1px;
		border-style: solid;
		border-color: white;
		background-color: white;
		border-radius: 10px;
		border-width: 10px;
		border-top-width: 5px;
		border-bottom-color: #f3f5f9;
		border-bottom-style: none;
	}

	.team {
		border: 1px;
		border-color: white;
		border-style: solid;
		background-color: white;
		border-radius: 10px;
		border-left-width: 15px;
		border-right-width: 15px;
		border-bottom-width: 5px;
	}

	.aaa {
		border: 2px;
		border-color: #f3f5f9;
		border-style: solid;
		background-color: #f3f5f9;
		border-radius: 7px;
		width: 100%;
	}

	
	.ccc{
		border: 1px;
		border-color: white;
		border-style: solid;
		background-color: white;
		border-radius: 10px;
		border-left-width: 15px;
		border-right-width: 15px;
		border-bottom-width: 5px;
		width: 320px;
	}
</style>